package com.workingpub.commons.jdbc;

import java.util.HashMap;
import java.util.Map;

import org.springframework.util.CollectionUtils;

/**
 * Map封装类，以Map的形式传递参数：
 * <li>SQL变量绑定</li>
 * <li>OGNL计算</li>
 * <li>可传递一般对象类型(String)和复杂对象类型(UserInfo)</li>
 * 
 * @author taoping
 *
 */
public class SqlParameters {
	private Map<String, Object> parameters;

	public static SqlParameters create() {
		return new SqlParameters();
	}

	public static SqlParameters create(String key, Object value) {
		return create().put(key, value);
	}

	public SqlParameters() {

	}

	public SqlParameters put(String key, Object value) {
		this.getParameters().put(key, value);
		return this;
	}

	public SqlParameters putAll(Map<String, ?> values) {
		if (CollectionUtils.isEmpty(values)) {
			return this;
		}
		this.getParameters().putAll(values);
		return this;
	}

	public Map<String, Object> map() {
		return this.parameters;
	}

	public boolean isEmpty() {
		return this.parameters.isEmpty();
	}

	protected Map<String, Object> getParameters() {
		if (null == parameters) {
			this.parameters = new HashMap<String, Object>();
		}
		return parameters;
	}

}
